//
//  HJInputViewController.m
//  Sneakers
//
//  Created by 胡光健 on 2017/11/8.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HJInputViewController.h"
#import "HJIputCell.h"
#import "HJOrderDetailModel.h"

@interface HJInputViewController ()
@property (weak, nonatomic) IBOutlet UIView *btmView;
@property (weak, nonatomic) IBOutlet UITextField *inputNum;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *btmY;


@property(nonatomic,strong) HJEXpressMSGModel * model;
@end

@implementation HJInputViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navTitle = @"录入单号";
    self.inputNum.layer.borderWidth = 0.5;
    self.inputNum.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.btmView.layer.shadowOpacity = 0.2;
    self.btmView.layer.shadowRadius = 3;
    self.btmView.layer.shadowOffset = CGSizeZero;
    self.btmView.layer.shadowColor = [UIColor blackColor].CGColor;
    [self.view bringSubviewToFront:self.btmView];
    
    if (mScreenHeight<812.0f) {
        self.btmY.constant = 0.0f;
    }else {
        self.btmY.constant = 34.0f;
    }
    
    [self loadWork];
}

-(void)configTableView {
    self.tableViewStyle = UITableViewStylePlain;
    [super configTableView];
    CGFloat H;
    if (mScreenHeight<812) {
        H = mScreenHeight -64-60;
    }else {
        H = mScreenHeight -TabBar_H-60;
    }
    self.tableView.frame = CGRectMake(0, 0, mScreenWidth, H);
    [self.tableView registerCellByNibName:@"HJIputCell"];
}
-(void)loadWork {
    [TZHttpTool post:ExpressaAddMSGAPI params:@{@"sell_id":self.sell_id} success:^(NSDictionary *result) {
        self.model = [[HJEXpressMSGModel alloc]init];
        self.model = [HJEXpressMSGModel mj_objectWithKeyValues:result[@"data"]];
        [self.tableView reloadData];
    } failure:^(NSString *msg) {
        [self showErrorHUDWithError:msg];
    }];
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HJIputCell * cell = [tableView dequeueReusableCellWithIdentifier:@"HJIputCell"];
    cell.selectionStyle =UITableViewCellSelectionStyleNone;
    cell.model = self.model;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 120;
}

- (IBAction)saveBtn:(UIButton *)sender {
    if ([CommonTools isEmpty:self.inputNum.text]) {
        [self showErrorHUDWithError:@"内容不能为空!"];
    }else {
        [TZHttpTool post:ExpressaAddAPI params:@{@"sell_id":self.sell_id,@"express":self.inputNum.text} success:^(NSDictionary *result) {
            [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
            [self showSuccessHUDWithStr:@"录入成功"];
        } failure:^(NSString *msg) {
            [self showErrorHUDWithError:msg];
        }];
    }
}

@end
